<?PHP

//get media processor
include 'm/media/p_media_content.php';

if($_POST['delete']=='delete')
{
	mp('delete');
	$f=get_data_form($table,$id);

	mp($f['image']);
	
	//deletesql($table,$id,$_POST['id']);
	//deletesql('content_video',$id,$_POST['id']);
	//deletesql('content_image',$id,$_POST['id']);
	$_POST['cmd']='';
	$_GET['cmd']='add';
}
if($_GET['cmd']=='edit')
{
	
	$f=get_data_form($table,$id);
	$i=get_data_form('content_image',$id);
	$g=get_data_form('content_video',$id);
	$j=get_data_form('content_meta',$id);
	$k=get_data_form('content_access',$id);
}
if($_POST['cmd']=='add' && !empty($_POST[$catch]))
{
			$post=process_default_serialized_values($post);
			process_sql_post($post,$table,'add',NULL,NULL);
			
			$post['id']=mysql_insert_id();
			if(!empty($image_data))
			{
				printmessage('Replacing Image Data');
				$image_data['id']=mysql_insert_id();
				
				process_sql_post($image_data,'content_image','add',NULL,NULL);		
			}
			else
			{
				printmessage('Adding Image Data');
				$image_data['id']=mysql_insert_id();
				$image_data['image']='20110511_sgv-pinoytuner-site-update-may-2011.jpg';
				$image_data['thumb']='20110511_iwb-pinoytuner-site-update-may-2011.jpg';
				process_sql_post($image_data,'content_image','add',NULL,NULL);		
			}
			
			process_sql_post($post,'content_video','add',NULL,NULL);
			process_sql_post($post,'content_meta','add',NULL,NULL);
			process_sql_post($post,'content_access','add',NULL,NULL);
		//	process_sql_post($post,'content_social','add',NULL,NULL);

	printmessage('Successfully Added');
}
else if($_POST['cmd']=='edit')
{			
		printmessage('Editing');
			$post['id']=$_GET[$id];
			$post=process_default_serialized_values($post);
			process_sql_post($post,$table,'update',$id,$_GET[$id]);
			if(empty($g))
			{
				process_sql_post($post,'content_video','replace',$id,$_GET[$id]);
			}
			else
			{
				process_sql_post($post,'content_video','update',$id,$_GET[$id]);
			}
			
			if(empty($j))
			{
			
				process_sql_post($post,'content_meta','replace',$id,$_GET[$id]);
			}
			else
			{
			
				process_sql_post($post,'content_meta','update',$id,$_GET[$id]);
			}
			
				if(empty($k))
				{

					process_sql_post($post,'content_access','replace',$id,$_GET[$id]);
				}
				else
				{

					process_sql_post($post,'content_access','update',$id,$_GET[$id]);
				}
			
		//	process_sql_post($post,'content_social','update',$id,$_GET[$id]);
			printmessage('Successfully Modified');
			
			rp($image_data);
			if(!empty($image_data))
			{
				printmessage('Replacing Image Data');
				$image_data['id']=$_GET[$id];
				if(empty($i))
				{
					process_sql_post($image_data,'content_image','add',$id,$_GET[$id]);	
				}
				else
				{
					process_sql_post($image_data,'content_image','update',$id,$_GET[$id]);	
				}
					
			}
}

if($_GET['cmd']=='edit' && isset($_GET[$id]))
{
	$f=get_data_form($table,$id);
	$i=get_data_form('content_image',$id);
	$g=get_data_form('content_video',$id);
	$j=get_data_form('content_meta',$id);
		$k=get_data_form('content_access',$id);
//	$h=get_data_form('content_social',$id);
	$e=array_merge((array)$f,(array)$i,(array)$g,(array)$j);
	rp($e);
	$e['id']=$_GET[$id];
	if($e['serial'] == 'N;' || empty($e['serial']) )
	{
	
			
	}
	else
	{
			$serial=unserialize($e['serial']);
			$e=array_merge($e,$serial);	
	}

}

?>